﻿using System.Collections.Generic;
using LogSystem;
using UnityEngine;
using XLua;
#if UNITY_EDITOR
using UnityEditor;
#endif

namespace ImageEffects
{
    public class DynamicLightElement : LightElement
    {
        /// <summary>
        /// 添加渲染器
        /// </summary>
        /// <param name="renderer"></param>
        public void AddLightRenderers(GameObject go)
        {
            if (LightRenderers == null)
            {
                LightRenderers = new List<Renderer>();
            }
            Renderer[] renderers = go.GetComponentsInChildren<Renderer>();
            foreach (var renderer in renderers)
            {
                LightRenderers.Add(renderer);
            }
        }
        
        public void RemoveLightRenderer(Renderer renderer)
        {
            if (LightRenderers == null)
            {
                return;
            }
            LightRenderers.Remove(renderer);
        }

        public void Refresh()
        {
            if (_isAdded)
            {
                _lightController.RemoveLightingElement(this);
            }
            AddToLightController();
        }
        
    }

}
